﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design.WebControls;
using System.Web.UI.Design;

namespace WebSlices.Design
{
    /// <summary>
    /// Provides designer functionality for the <see cref="WebSlice"/> control.
    /// </summary>
    public class WebSliceDesigner : ContainerControlDesigner
    {
        /// <summary>
        /// Returns the HTML markup that is used to represent the control at design time.
        /// </summary>
        /// <param name="regions">A collection of designer regions.</param>
        /// <returns>
        /// An HTML markup string that represents the control.
        /// </returns>
        public override string GetDesignTimeHtml(DesignerRegionCollection regions)
        {
            IResourceUrlGenerator service = (IResourceUrlGenerator)this.Component.Site.GetService(typeof(IResourceUrlGenerator));

            if (service != null)
            {
                string url = service.GetResourceUrl(typeof(WebSliceDesigner), "WebSlices.Resources.WebSliceLogo.png");

                StringBuilder html = new StringBuilder();
                html.Append("<img src=\"" + url + "\" style=\"position: absolute;\"/>");
                html.Append(base.GetDesignTimeHtml(regions));

                return html.ToString();
            }

            return base.GetDesignTimeHtml(regions);
        }
    }
}